<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!doctype html>
<html>
<head>
<title>理陪单管理</title>
<%@ include file="../common/base.jsp" %>
</head>

<body id="body">
<!--head-->
<div id="head">
	<%@ include file="../common/head.jsp" %>
</div>
<!--head end-->
<!--container-->
<div id="container">
	<div id="pageId" style="display: none;">02-10-01</div>
		<!--sidebar-->
		<%@ include file="../common/menu.jsp" %>
	    <!--sidebar-->
    <!--main-->
    <div class="main">
    	<div class="location" style="background-position:22px -109px;">
        	平台管理<span>&gt;</span>理陪管理<span>&gt;</span>理陪信息管理
        </div>
        <!--content-->
        <div class="content">
			<div class="info_container">
				<i style="display:inline-block;">
					<label style="width:210px;text-align:right;min-width:200px;margin-right:6px;" >理陪单状态：
						<div class="requery_box">
							<select id="state" name="state" style="width: 120px;">
								<option value="-1">全部</option>
								<c:forEach var="item" items="${dictList}" varStatus="vatS">
									<option value="${item.enumCode}">${item.enumName}</option>
								</c:forEach>
							</select>
						</div>
					</label>
				</i>
				<label style="width: 450px" >
					<i class="sel_date">时间选择：</i>
					<input type="text" id="startTime" class="Wdate"
						   onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'1990-01-01'});this.style.border = '1px solid #2A7CCF'" onBlur="this.style.border = '1px solid #D5D5D5'"
						   value="${startTime}"
						   readonly/>
					—
					<input type="text" id="endTime" class="Wdate"
						   onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'1990-01-01'});this.style.border = '1px solid #2A7CCF'" onBlur="this.style.border = '1px solid #D5D5D5'"
						   value="${endTime}"
						   readonly/>
				</label>
				<button type="button" class="btn btn_search" id="query_button"></button>
			</div>
            <div id="tableResult">
            	<table class="table_type1">
	                <thead>
	                    <tr>
	                        <th>序号</th>
	                        <th>保单编号</th>
							<th>理陪单状态</th>
	                        <th>理陪金额</th>
	                        <th>理陪次数</th>
	                        <th>保单总金额</th>
	                        <th>保单总次数</th>
							<th>申请时间</th>
	                        <th>操作</th>
	                    </tr>
	                </thead>
	                <tbody id="bodyResult"></tbody>
	            </table>
            </div>
            <div class="page">
                	<div class="itemNum" >
		                    	显示：<select id="selItem">
		                    			<option selected="selected" id="20">20</option>
		                    			<option id="30">30</option>
		                    			<option id="40">40</option>
		                    			<option id="50">50</option>
		                    		</select>条，共 <a id="totalCount" onclick="javascript:void(0);" ></a> 条
		            </div>
                    <ul class="pagination" id="pageCur"></ul>
            </div>
        </div>
		<!--遮罩层-->
		<div id="mask" style="display:none;"></div>
		<!--遮罩层-->
		<!--弹出框-->
		<div id="popBox" class="popBox2" style="display:none;">
			<h2></h2>
			<a href="javascript:;" class="close" onClick="closeHide();"></a>
			<div id="popBox_con1" style="display:none;">
				<div class="pop_content" style="height: 240px;">
					<ul class="recharge_list tzz_list pop_list" style="width:60%">
						<li class="tzz_code" style="height:auto;">
							<label style="width:28%;">预约送车开始时间：</label>
							<input type="text" id="sendStartTime" class="Wdate"
								   onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'1990-01-01'});this.style.border = '1px solid #2A7CCF'" onBlur="this.style.border = '1px solid #D5D5D5'"
								   value="${sendStartTime}"
								   readonly/>
						</li>
						<li class="tzz_code" style="height:auto;">
							<label style="width:28%;">预约送车结束时间：</label>
							<input type="text" id="sendEndTime" class="Wdate"
								   onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'1990-01-01'});this.style.border = '1px solid #2A7CCF'" onBlur="this.style.border = '1px solid #D5D5D5'"
								   value="${sendEndTime}"
								   readonly/>
						</li>
						<li class="tzz_code" style="height:auto;">
							<label style="width:28%;">维修单指派修理中心：</label>
							<select id="repairId" name="repairId" style="width: 120px;">
								<option value="-1">全部</option>
								<c:forEach var="item" items="${repairList}" varStatus="vatS">
									<option value="${item.id}">${item.province}-${item.repairName}</option>
								</c:forEach>
							</select>
						</li>

					</ul>
				</div>
				<div class="pop_button">
					<a href="javascript:;" onClick="divSubmit();">提交</a>
					<a href="javascript:;" onClick="closeHide();">关闭</a>
				</div>
			</div>
		</div>
        <!--content-->
        <!--foot--><%@ include file="../common/foot.jsp" %>
        <!--foot-->
    </div>
    <!--main-->
</div>
<!--container-->
<script src="${pageContext.request.contextPath}/static/js/basic.js"></script>
<script type="text/javascript">
	var claimId = 0;
    var Ocon1=document.getElementById('popBox_con1');
    var Omask=document.getElementById('mask');
    var OpopBox=document.getElementById('popBox');
    function assignClaim(id){
        Omask.style.display='block';
        OpopBox.style.display='block';
        Ocon1.style.display='block';
        claimId = id;
    }

    function closeHide(){
		$("#cause").text("");
        $("#popBox").hide();
        $("#mask").hide();
    }

    function divSubmit(){
        var repairId = $("#repairId").val();
        if(repairId == null || repairId.length < 1 || repairId ==""){
            prompt.alert("请选择理陪单指派的修理厂！");
		}
		var repairName = $("#repairId").find("option:selected").text();
        var sendStartTime = $("#sendStartTime").val();
        var sendEndTime = $("#sendEndTime").val();

        prompt.confirm("您确定指派该"+repairName+"吗?",function(){
			$.ajax({
				type: "POST",
				url: "${pageContext.request.contextPath}/claim/assignClaim",
				dataType:"json",
				data: {
					"id":claimId,
					"repairId":repairId,
					"sendStartTime":sendStartTime,
					"sendEndTime":sendEndTime
				},
				success: function(data){
					if (data.errorCode==0) {
						closeHide();
						prompt.alert("理陪单指派修理厂成功！");
						setTimeout(function(){
							loadResult(1,$("#selItem").val());
						},2000);
					}else{
						prompt.alert(data.msg);
					}
				}
			});
		});

    }

	function showInquiryOrder(id){
        window.location.href = "${pageContext.request.contextPath}/claim/showInquiryOrder?id="+id;
	}




//加载ajax请求
function loadResult(page,numPerPage){
	loadResultPerfect(page,numPerPage,"claim/queryClaimDate",retParam());
}

// 加载ajax返回结果
function loadTableResult(data){
	var jo = data.json;
	if(jo != '' && jo != null){
		for (var i = 0; i < jo.length; i++) {
		    var opHtml = "<a href='claim/showClaimDetail?id=" + jo[i].id + "'>理陪单详情</a>&nbsp;";

		    var stateName = "理陪完成";
		    var state = jo[i].status;
		    if(state ==1){
                stateName = "申请中";
                opHtml = opHtml+"<a href='javaScript:void(0)' onclick='assignClaim("+jo[i].id+")'>预约修理厂</a>";
			}else if(state ==2){
                stateName = "已预约送车时间";
			}else if(state ==3){
                stateName = "已送车";
            }else if(state ==4){
                stateName = "修理中";
            }else if(state ==5){
                stateName = "已接车";
            }else if(state ==7){
                stateName = "未送车";
            }else if(state == 8){
                stateName ="修理中心报价";
                opHtml = opHtml+"<a href='javaScript:void(0)' onclick='showInquiryOrder("+jo[i].id+")'>修理厂报价单</a>";
			}else if(state == 9){
                stateName ="平台报价";
            }else{
                stateName = "理陪完成";
			}

			var content = "<tr>"+
	                    	"<td>"+(i+1)+"</td>" +
							"<td>"+jo[i].policyId+"</td>" +
							"<td>"+stateName+"</td>" +
                			"<td>"+jo[i].claimSafeMoney+"</td>" +
							"<td>"+jo[i].claimSafecount+"</td>" +
							"<td>"+jo[i].safeMoney+"</td>" +
							"<td>"+jo[i].safeCount+"</td>" +
							"<td>"+dateFormatTimeLong(jo[i].createTime)+"</td>" +
	                    	"<td>"+opHtml+"</td>"+
	                      "</tr>";
	        $("#bodyResult").append(content);
	    }
	}
}



function addSubmit(){
	window.location.href = "${pageContext.request.contextPath}/aiche/showSaveOrUpdateProduct?type=save";
}

function retParam(){
    var param =  "startTime=" + $("#startTime").val() +
        "&endTime=" + $("#endTime").val() +
        "&state=" + $("#state").val();
    return param;
}

//表格排序表头样式
$(document).ready(function(e) {
	loadResult(1,$("#selItem").val());
});

</script>
</body>
</html>